<template>
  <div id="NotIdentified" :class="{smallFontSize:showEdition,mediumFontSize:!showEdition}">
    <div v-if="isShow" style="height: 100vh;overflow-y: auto">
      <div>
        <form action="/">
          <van-search
            style="
           width: calc(100% - 4px);
           background: #EEE;
           border-radius: 10px;
           height:40px;
           font-size: 14px;
           float: left"
            v-model="SearchData"
            placeholder="请输入信息"
            @search="onSearch"
          />
        </form>
      </div>
      <div>
        <van-list  >
          <van-cell v-for="(item, index) in contentData" @click="contentClick(item)" :key="index">
            <ul>
              <li>
                <p style="margin-bottom: 8px; height: 3vh">
                  <span style="font-weight: bold;">{{ item.propertyPerson }}</span>
                  <span style="float: right">
                    <span >当前状态：{{item.appraiseStatus}}</span>
                  </span>

                </p>
                <p  style="margin-bottom: 8px; height: 3vh">
                  <span>排查编号：{{ item.checkNumber }}</span>
                </p>

                <p style="clear: both; display: flex; align-items: center">
                  <img
                    style="margin-right: 4px"
                    width="10"
                    src="https://nfzjszlb.jst.zj.gov.cn/serverfile/zheliban/icon/YPC/dingwei.png"
                  />
                  <span  style="font-size: 14px; color: blue">
                  {{ item.belongCity}}{{ item.belongCountry}}{{ item.belongTown}}{{ item.belongVillage}}
                </span>
                </p>
              </li>
            </ul>
          </van-cell>
        </van-list>
      </div>
    </div>
    <div v-if="!isShow">
      <div style="height: 84vh;overflow:auto;">
        <van-field readonly clickable name="picker" v-model="JBXXform.isFarmHouse" label="是否农村房屋" placeholder="请选择"
                   @click="showPicker = true" />
        <van-popup v-model="showPicker" position="bottom" get-container="#popup">
          <van-picker  show-toolbar :columns="columns" @confirm="onConfirm"
                      @cancel="showPicker = false" />
        </van-popup>
        <van-field readonly v-model="userType" label="是否困难家庭(来源于大数据接口)"  />
        <van-field name="switch" label="是否修改">
          <template #input>
            <van-switch v-model="value" size="20" />
          </template>
        </van-field>
        <div v-if="value">
          <p style="width: 100%;text-align: center;font-weight: bold;padding: 10px;">困难家庭信息</p>
          <van-field readonly clickable name="picker" v-model="KNJTuserType" label="是否困难家庭" placeholder="请选择"
                     @click="showPicker1 = true" />
          <van-popup   v-model="showPicker1" position="bottom" get-container="#popup">
            <van-picker value-key="name" show-toolbar :columns="columns1" @confirm="onConfirm1"
                        @cancel="showPicker1 = false" />
          </van-popup>
          <van-field
            v-model="KNJTform.remark"
            rows="3"
            autosize
            label="理由"
            type="textarea"
            placeholder="请输入审核意见"
          />
        </div>
        <div v-if="JBXXform.isFarmHouse=='是'">
          <p style="width: 100%;text-align: center;font-weight: bold;padding: 10px;">鉴定信息</p>
          <van-field readonly clickable name="picker" v-model="JBXXform.isAuth" label="无需鉴定可直接整治" placeholder="请选择"
                     @click="showPicker2 = true" />
          <van-popup v-model="showPicker2" position="bottom" get-container="#popup">
            <van-picker  show-toolbar :columns="columns" @confirm="onConfirm2"
                         @cancel="showPicker2 = false" />
          </van-popup>
          <van-field v-if="JBXXform.isAuth=='是'" readonly v-model="JBXXform.authLevel" label="房屋等级" placeholder="请填写统一社会信用代码" />
          <!--<van-field v-if="JBXXform.isAuth=='是'" readonly clickable name="picker" v-model="JBXXform.isAuth" label="房屋等级" placeholder="请选择"-->
                     <!--@click="showPicker = true" />-->
          <!--<van-popup v-model="showPicker" position="bottom" get-container="#popup">-->
            <!--<van-picker  show-toolbar :columns="columns" @confirm="onConfirm"-->
                         <!--@cancel="showPicker = false" />-->
          <!--</van-popup>-->
          <van-field v-if="JBXXform.isAuth=='否'" readonly clickable name="picker" v-model="JBXXform.authCompanyName" label="鉴定机构" placeholder="请选择"
                     @click="showPicker3 = true" />
          <van-popup v-model="showPicker3" position="bottom" get-container="#popup">
            <van-picker value-key="qymc" show-toolbar :columns="JDJGData" @confirm="JDJGChange"
                         @cancel="showPicker3 = false" />
          </van-popup>
          <van-field v-if="JBXXform.isAuth=='否'" v-model="JBXXform.socialCreditCode" label="统一社会信用代码" placeholder="请填写统一社会信用代码" />
          <van-field v-if="JBXXform.isAuth=='是'"  name="uploader" label="房屋现场照片">
            <template #input>
              <van-uploader
                ref="uploadFile"
                :after-read="afterRead"
                :before-delete="delectFile"
                v-model="fileList"
              />
            </template>
          </van-field>
          <van-field v-if="JBXXform.isAuth=='是'"  name="uploader" label="房屋现场照片">
            <template #input>
              <van-uploader
                ref="uploadFile"
                :after-read="afterRead"
                :before-delete="delectFile"
                v-model="fileList"
              />
            </template>
          </van-field>
        </div>
      </div>
      <div class="footer" v-if="rowData.appraiseStatus!='已委托'">
        <van-button   style="width: 40%;" :style="{fontSize:showEdition?'14px':'20px'}"  type="info" @click="saveData()">保存</van-button>
        <van-button  style="width: 40%;" :style="{fontSize:showEdition?'14px':'20px'}"  type="info" @click="saveData('submit')">提交</van-button>
      </div>
    </div>
  </div>
</template>

<script>
  import axios from 'axios'
  export default {
    name: "NotIdentified",
    data() {
      return{
        KNJTuserType:'',
        userType:'',
        isLongData:false,
        JDJGData:"",
        value:false,
        KNJTform: {
          remark: '',
          userType: '',
          objectNo: ''
        },
        JBXXform: {
          objectNo: '',
          userName: "",  // 处理人名称
          userId: "",  // 处理人id
          isAuth: '',
          authLevel: '',
          authCompanyName: '',
          socialCreditCode: '',
          recheck:0,
          isFarmHouse: '',
          fileHousePicture: ''
        },
        SearchData:'',
        showEdition: false,
        loading: false,
        finished: false,
        contentData:[],
        isShow:true,
        showPicker:false,
        showPicker1:false,
        showPicker2:false,
        showPicker3:false,
        columns:["是","否"],
        columns1:[
          {
            name:'是',
            value:'1'
          },
          {
            name:'否',
            value:'0'
          }
        ],
        formData:{
          ZLFS:'',
          BLR:'',
          BLSJ:""
        },
        showPickerq:false,
        currentDate: new Date(),
        formArry:[
          {
            name:'姓名',
            prop:'XM'
          },
          {
            name:'身份证号',
            prop:'XM'
          },
          {
            name:'性别',
            prop:'XM'
          },
          {
            name:'出生年月',
            prop:'XM'
          },
          {
            name:'联系电话',
            prop:'XM'
          },
          {
            name:'证书编号',
            prop:'XM'
          },
          {
            name:'技能',
            prop:'XM'
          },
          {
            name:'文化程度',
            prop:'XM'
          },
          {
            name:'常住地址',
            prop:'XM'
          },
          {
            name:'从业年限(仅限数字)',
            prop:'XM'
          },
        ],
        fileList:[],
        BaseURL:window.g.BaseURL,
        rowData:""
      }
    },
    methods:{
      //上传附件
      afterRead: async function (file) {
        console.log(file)
        // console.log(this.fileList)
        var formData = new FormData();
        formData.append("files", file.file);
        formData.append('path', 'wg')
        formData.append("groupName", "房屋现场照片");
        formData.append("toGroupGuid", this.groupGuid);
        let webResult = await axios.post(this.BaseURL + '/api/upload/oss/files', formData, {
          headers: {
            isOutParam: true,
          },
        });
        console.log(webResult)
        if (webResult.data && webResult.data.data) {
          this.JBXXform.fileHousePicture = this.groupGuid
          file.id = webResult.data.data[0].id
          this.$message.success("上传成功")
        } else {
          file.status = 'failed';
          file.message = '上传失败';
        }
      },
      //删除附件
      delectFile:async function(file, fileList) {
        console.log(file, fileList)
        let arr = [];
        arr.push(file.id)
        let webResult = await axios.post(this.BaseURL + 'api/upload/oss/delete', arr, {
          headers: {
            isOutParam: true,
            isOutParamS: true,
          },
        });
        if (webResult.data.data) {
          // this.uploadlist.forEach(item => {
          this.fileList.forEach((items, index) => {
            if (items.id == file.id) {
              this.fileList.splice(index, 1)
            }
          })
          // })
          this.$message.success(webResult.data.msg)
        } else {
          this.$message.error(webResult.data.msg)
        }
      },
      WXJDChange() {

      },
      onSearch(){
        this.getData()
      },
      contentClick(item){
        // alert(1)
        this.isShow = false
        this.rowData = item
        this.userType = this.rowData.userType=='1'?'是':'否'
        this.getJDXXList()
        this.getDifficultNew()
      },
      onConfirmRQ(){

      },
      getData: async function() {
        let parm1 = {
          "belongCountryList": [],
          "belongCountyList": [],
          "name": "",
          "pageNo": 1,
          "pageSize": 100
        }
        let webResult1 = await axios.post(this.BaseURL + '/api/farmerHouse/zhejiangHouseTechnicalUnit/selectTechnicalList', parm1, {
          headers: {
            isOutParam: true,
          },
        });
        this.JDJGData = webResult1.data.data.pageList
        let parm = {
          cityCode:  window.localStorage.getItem('citycode').replace(/(0+)$/g, ""),
          pageNo: 1,
          pageSize: 100,
          propertyPerson:this.SearchData
        }
        let webResult = await axios.post(this.BaseURL + '/api/farmerHouse/dangerHouseRemold/list', parm, {
          headers: {
            isOutParam: true,
          },
        });
        console.log(webResult)
        this.contentData = webResult.data.data.pageList
      },
      onConfirm(data) {
        this.JBXXform.isFarmHouse = data
        this.showPicker = false

      },
      onConfirm1(data) {
        this.KNJTform.userType = data.value
        this.KNJTuserType =  data.name
        this.showPicker1 = false
      },
      onConfirm2(data){
        this.JBXXform.isAuth = data
        this.showPicker2 = false
        this.JBXXform.authLevel = "D"
      },
      JDJGChange(data) {
        this.JBXXform.authCompanyName = data.qymc
        this.JDJGData.forEach(item=>{
          if (item.qymc == data.qymc) {
            this.JBXXform.socialCreditCode = item.zzjgdm
          }
        })
        this.showPicker3 = false
      },
      //信息回显
      getJDXXList: async function() {
        let parm = {
          "objectNo": this.rowData.objectNo,
          "recheck": "0"
        }
        let webResult = await axios.post(this.BaseURL + '/api/farmerHouse/dangerHouseRemold/authInfo', parm, {
          headers: {
            isOutParam: true,
          },
        });
        console.log(webResult)
        if(webResult.data){
          this.JBXXform.isFarmHouse = webResult.data.isFarmHouse
          if (webResult.data.fileHousePicture) {
            this.groupGuid = webResult.data.fileHousePicture
          }
          if (webResult.data.fileHousePictureUrlList) {
            webResult.data.fileHousePictureUrlList.forEach((item)=>{
              this.fileList.push({
                id: item.id,
                url: this.BaseURL + "api/upload/oss/preview?fileId=" + item.id,
                name: item.fileName,
              })
            })
          }
          if(webResult.data.companyName){
            this.JBXXform.authCompanyName = webResult.data.companyName;
            this.JBXXform.socialCreditCode = webResult.data.companyUscc;
            this.JBXXform.isAuth='否'
          }else{

            this.JBXXform.isAuth='是'
            this.JBXXform.authLevel = "D"
          }
        }
        // this.JBXXform=webResult.data;
      },
      saveData: async function(type) {
        console.log(this.JBXXform)
        this.JBXXform.objectNo = this.rowData.objectNo
        if (this.value) {
          for (let i in this.KNJTform) {
            this.KNJTform.objectNo = this.rowData.objectNo
            // this.KNJTform.userName = Eca.CurrentUser.username
            // this.KNJTform.userId = Eca.CurrentUser.userid

            if (this.KNJTform[i] !== '') {
              // alert(i)

            } else {
              this.$message.error("请填写困难家庭信息!");
              return;
            }
          }
          console.log(this.KNJTform)
        }
        if (this.JBXXform.isFarmHouse == '是') {
          if (this.JBXXform.isAuth == '否' && !this.JBXXform.authCompanyName && !this.JBXXform.authCompanyName) {
            this.$message.error("请填写必填项!");
            return;
          }
        } else {
          this.JBXXform.authLevel = ""
          this.JBXXform.isAuth = ""
        }
        let webResult = await axios.post(this.BaseURL + '/api/farmerHouse/dangerHouseRemold/saveAuthInfo', this.JBXXform, {
          headers: {
            isOutParam: true,
          },
        });
        if (webResult.data.data) {
          if (type == "submit") {
            this.updateData();
          } else {
            this.$message.success("保存成功")
          }
        } else {
          this.$message.error("保存失败")
        }
        if (this.value) {
          if(this.isLongData){
            this.KNJTform.userTypeFirst="1";
          }
          let webResult1 = await axios.post(this.BaseURL + '/api/farmerHouse/dangerHouseRemold/saveUserType', this.KNJTform, {
            headers: {
              isOutParam: true,
            },
          });
          if (webResult1.data.msg == '成功') {
            // this.$message.success("保存成功")
          } else {
            this.$message.error("保存失败")
          }
        }
      },
      //困难家庭大数据接口
      getDifficultNew: async function(){
        var  param={
          "householderName": "",//param.householderName,
          "idCard":this.rowData.householderIdCard,// param.idCard,
          "type": 0
        };
        let webResult = await axios.post(this.BaseURL + '/api/farmerHouse/share/getDifficultFamilies', param, {
          headers: {
            isOutParam: true,
          },
        });
        if(webResult.data.data){
          this.isLongData = true;
        }
        console.log(webResult)
      },
      updateData: async function() {
        this.disabled = false
        let webResult = await axios.post(this.BaseURL + '/api/farmerHouse/dangerHouseProcess/appraisal', this.JBXXform, {
          headers: {
            isOutParam: true,
          },
        });
        console.log(webResult.data.data)
        if (webResult.data.data) {
          this.disabled = true
          this.$message.success("提交成功");
          this.backHomepage();
        } else {
          this.$message.error("提交失败")
        }
      },
      backHomepage() {
        this.getData()
        this.isShow = true
      },
    },
    mounted() {
      this.groupGuid = this.newGuid()
      this.showEdition = this.$store.state.Edition
      this.getData()

    }
  };
</script>

<style scoped lang="scss">
  #NotIdentified{
    padding: 10px;
    text-align: center;
    .footer{
      width: 95%;
      position: fixed;
      bottom: 10px;
    }
  }
</style>
